<?php

if(isset($_GET['logout'])){
	header('Cache-control: private');
	header('Location:'. HOST_NAME.'index.php'); /* Redirect browser */
	$_SESSION = array();
	session_destroy();
	exit();
}elseif(isset($_POST['sub']) and substr($_SERVER['REQUEST_URI'],-6)=='admin/') {// if form has been submitted
	
}elseif(isset($_SESSION['ablogin'])){// if cookie isset
	$o_Login = unserialize($_SESSION['ablogin']);
	if($o_Login->isLogin()){
		if(substr($_SERVER['REQUEST_URI'],-9)=='index.php' or substr($_SERVER['REQUEST_URI'],-6) == 'admin/'){
			header('Location:'.HOST_NAME.'admin/todo.php');
			exit;		
		}
	}
} elseif(substr($_SERVER['REQUEST_URI'],-6)!='admin/' and substr($_SERVER['REQUEST_URI'],-9)!='index.php'){
	$_SESSION['last'] = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
	$errormsg='Necesitas idetificarte en el sistema';
	header('Location:'. HOST_NAME.'admin/');
}
?>
